#ifndef TIMER_H_

#define TIMER_H_

#include "event.h"
#include "eventhandler.h"
#include "common.h"

class Timer : public Event{
	public:
		Timer( EventHandler *h ) 
			: Event(Event::TIMER, h)
			, timer_id_( timer_id_count_++ )
		{}

		uint32_t id() const { return timer_id_; }

	protected:
		uint32_t timer_id_;
		static uint32_t timer_id_count_;
};

class TimerHandler : public EventHandler, public Object{
	public:
		enum STATUS{
			TIMER_PENDING, 
			TIMER_IDLE
		};
		TimerHandler()
		: status_( TIMER_IDLE ){
			NEW_OBJECT( Timer, timer_, (this) );
		}
		~TimerHandler(){
			RELEASE_OBJ( timer_ );
		}

		void sched( sim_time_t delay );
		void resched( sim_time_t delay );

		virtual void onEvent( Event *event ){}
		virtual void onTimer( Timer *timer ){
			status_ = TIMER_IDLE;
		}
	private:
		Timer *timer_;
		STATUS status_;
};

#endif /* TIMER_H_ */

